/*
 * Created on 2004-05-10
 */
package jaoso.framework.service.impl;

import jaoso.framework.dao.PersistentManager;
import jaoso.framework.dao.QueryManager;

import jaoso.framework.service.IService;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author ��Ե�¿� edgeloner@163.com
 */
public abstract class BaseService implements IService
{
    /**
     * DOCUMENT ME!
     */
    private static Log log = LogFactory.getLog(BaseService.class);

    /**
     * DOCUMENT ME!
     */
    private PersistentManager persistentManager;

    /**
     * DOCUMENT ME!
     */
    private QueryManager queryManager;

    /**
     * DOCUMENT ME!
     * 
     * @param manager
     *            DOCUMENT ME!
     */
    public final void setPersistentManager(final PersistentManager manager)
    {
        persistentManager = manager;
    }

    /**
     * DOCUMENT ME!
     * 
     * @param manager
     *            DOCUMENT ME!
     */
    public final void setQueryManager(final QueryManager manager)
    {
        queryManager = manager;
    }

    /**
     * DOCUMENT ME!
     * 
     * @return DOCUMENT ME!
     */
    protected final PersistentManager getPersistentManager()
    {
        return persistentManager;
    }

    /**
     * DOCUMENT ME!
     * 
     * @return DOCUMENT ME!
     */
    protected final QueryManager getQueryManager()
    {
        return queryManager;
    }

    /**
     * DOCUMENT ME!
     * 
     * @param dto
     *            DOCUMENT ME!
     * @param entity
     *            DOCUMENT ME!
     * 
     * @return DOCUMENT ME!
     */
    protected final Object dto2Entity(final Object dto, final Object entity)
    {
        try
        {
            BeanUtils.copyProperties(entity, dto);
        } catch (Exception e)
        {
            log.error("dto to entity error: " + e);
        }

        return entity;
    }

    /**
     * DOCUMENT ME!
     * 
     * @param entity
     *            DOCUMENT ME!
     * @param dto
     *            DOCUMENT ME!
     * 
     * @return DOCUMENT ME!
     */
    protected final Object entity2Dto(final Object entity, final Object dto)
    {
        try
        {
            BeanUtils.copyProperties(dto, entity);
        } catch (Exception e)
        {
            log.error("dto to entity error: " + e);
        }

        return dto;
    }
}